package com.yisu.expressway.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;


import com.yisu.expressway.fragment.BaseFragment;
import com.yisu.expressway.shopping_mall.ShopCategoryFragment;
import com.yisu.expressway.model.ShopCategory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by theodore_hu on 2016/1/19.
 */
public class ShoppingMallTabAdapter extends FragmentPagerAdapter {
    List<BaseFragment> mListFragment = new ArrayList<BaseFragment>();
    FragmentManager mFm;
    ArrayList<ShopCategory> mCategoryList = new ArrayList<>();
    Fragment mFragment;

    public ShoppingMallTabAdapter(Fragment fragment,ArrayList<ShopCategory> tagList){
        super(fragment.getChildFragmentManager());
        mFm = fragment.getChildFragmentManager();
        mCategoryList = tagList;
        mFragment = fragment;
    }

    public void updateAdapter(String[] mTitleArray, ArrayList<ShopCategory> tagList){
        mCategoryList = tagList;
        notifyDataSetChanged();
    }

    @Override
    public BaseFragment getItem(int position) {
        BaseFragment fg;
        fg = new ShopCategoryFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ShopCategoryFragment.TAG_CONTENT, mCategoryList.get(position));
        fg.setArguments(bundle);
        return fg;
    }

    public BaseFragment getCurrentFragment(int position){
        if(position >= mListFragment.size() || mListFragment.size() == 0){
            return null;
        }
        return mListFragment.get(position);
    }

    @Override
    public int getItemPosition(Object object) {
        return PagerAdapter.POSITION_NONE;
    }


    @Override
    public int getCount() {
        return (mCategoryList != null) ? mCategoryList.size() : 0 ;
    }



}
